package com.zzx.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestController {
	@RequestMapping("/test")
	public String testSayHello(){
		System.err.println("***********controller**开始***********************");
		return "index";
	}
	@RequestMapping(value="/list",produces="text/plain;charset=UTF-8")
	public String testlist(Model model,HttpServletRequest request,HttpServletResponse response){
		System.err.println("***********list**开始***********************");
		model.addAttribute("name", "小明");
		
		return "list";
	}
	@RequestMapping(value="/add",produces="text/plain;charset=UTF-8")
	public String add(Model model,HttpServletRequest request,HttpServletResponse response){
		System.err.println("***********add**开始***********************");
		model.addAttribute("name", "小明");
		
		return "add";
	}
	@RequestMapping(value="/edit",produces="text/plain;charset=UTF-8")
	public String edit(Model model,HttpServletRequest request,HttpServletResponse response){
		System.err.println("***********edit**开始***********************");
		//model.addAttribute("name", "小明");
		Map<String,String> map = new HashMap<String,String>();
		map.put("id", "111");
		map.put("name", "小明");
		map.put("method", "edit");
		map.put("teacher", "老师");
		model.addAllAttributes(map);
		
		return "edit";
	}
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public String querylist(Model model,HttpServletRequest request,HttpServletResponse response){
		System.err.println("***********list**开始***********************");
		model.addAttribute("name", "小明");
		Map<String,Object> map = new HashMap<String,Object>();		
		map.put("status","success");
		map.put("type","1");
		map.put("message","返回列表成功");
		//map.put("data","data");
		List<Map<String,String>> list = new ArrayList<Map<String,String>>();
		Map<String,String> m = new HashMap<String,String>();
		m.put("id", "111");
		map.put("name", "小明");
		list.add(m);
		map.put("data", list);
		model.addAttribute("data", map);
		return "list";
	}
}
